/**
 * Created by zxl on 2020-03-31.
 */
import Instance from './Instance.js';
export default class CombotreeInstance extends Instance{
    constructor(seq){
        super();
        var label="树形选择"+seq;
        this.element=this.newElement(label);
        this.inputElement=$("<div>");
        //this.select=$("<select class='easyui-combotree' >");
        this.select=$("<input>");
        this.inputElement.append(this.select);
        this.element.append(this.inputElement);

        this.select.uniqueId();
        this.treeid=this.select.prop("id");
        //alert(this.treeid);
        this.initTree(this.treeid);

        this.element.uniqueId();
        this.id=this.element.prop("id");
    }
    initTree(treeid){
        setTimeout(function () {
            if (this.dataType && this.dataType!=''){

            }else{
                $('#'+treeid).combotree({
                    multiple: true,
                    editable: false,
                    cascadeCheck:false,
                    panelHeight: 'auto',
                    checkbox: true,
                    data: CombotreeInstance.initTreedata
                });
            }
        },200);
    }
    initFromJson(json){
        super.fromJson(json);
        if(json.searchOperator){
            this.searchOperator=json.searchOperator;
        }

        this.dataType=json.dataType;
        this.initTree(this.treeid)
    }
    toJson(){
        const json={
            label:this.label,
            optionsInline:this.optionsInline,
            labelPosition:this.labelPosition,
            bindParameter:this.bindParameter,
            type:CombotreeInstance.TYPE,
            dataType:this.dataType
        };
        return json;
    }
    toXml(){
        let xml=`<Combotree label="${this.label}" type="${CombotreeInstance.TYPE}" label-position="${this.labelPosition || 'top'}" bind-parameter="${this.bindParameter || ''}"`;
        xml+=` dataType="${this.dataType}"`;
        xml+='>';
        xml+=`</Combotree>`;
        return xml;
    }
}
CombotreeInstance.TYPE="Combotree";
CombotreeInstance.initTreedata =[{
    id: 1,
    text: '分类',
    children: [{
        id: 11,
        text: '项目一'
    },{
        id: 12,
        text: '项目二'
    }]
}];